package com.doeis.uwork.module;

import com.doeis.minaserver.NettyServer;
import com.doeis.minaserver.container.BasicModule;
import com.doeis.minaserver.session.ClientConnection;
import com.doeis.uwork.packet.GroupMsgPacket;
import com.doeis.uwork.servce.GroupMsgService;


public class GroupMsgPacketRouter extends BasicModule {

	private GroupMsgService groupMsgService;
	
	public GroupMsgPacketRouter() {
		super("Group Message Router");
	}
	
	public GroupMsgPacketRouter(String moduleName) {
		super(moduleName);
	}
	@Override
	public void start() {
		groupMsgService = server.getT(GroupMsgService.class);
	}

	@Override
	public void initialize(NettyServer server) {
		this.server = server;		
	}

	public void route(ClientConnection fromConn, GroupMsgPacket packet) {
		switch ( packet.getCmd() ) {
		
		case GroupMsgPacket.CMD_MSG_ADD://客户端向服务器发送>>>新增消息 
			groupMsgService.addMsg(fromConn, packet);
			break;
			
		case GroupMsgPacket.CONFIRM_MSG_ADD: //客户端接收到服务器通知消息，再次向服务器发送确认消息
			groupMsgService.comfirmAddMsg(fromConn, packet);
			break;
			
		case GroupMsgPacket.NOTIFY_MSG_ADD_OTHER_RE://客户端发送确认收到消息
			groupMsgService.acknowledgeReceipt(fromConn, packet);
			break;
			
		case GroupMsgPacket.CMD_MSG_LIST:
			groupMsgService.listMsg(fromConn, packet);
			break;
		case GroupMsgPacket.CMD_MSG_LIST_GMSG:
			groupMsgService.listMsg(fromConn, packet);
			break;
			
		case GroupMsgPacket.CMD_MSG_LIST_SHARE_USER:
			groupMsgService.listShareUser(fromConn, packet);
			break;
		case GroupMsgPacket.CMD_MSG_LIST_PICTURE:
			groupMsgService.listPicture(fromConn, packet);
			break;
		case GroupMsgPacket.CMD_MSG_LIST_LASTMSG:
			groupMsgService.listLastMsg(fromConn, packet);
			break;
		
		default:
			break;
		}		
	}

}
